<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>互动专区</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>发送者</label>
                                    <input type="text" name="sendUserName" class="form-control" placeholder="请输入名称">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>接收者</label>
                                    <input type="text" name="receiverUserName" class="form-control" placeholder="请输入名称">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>时间</label>
                                    <input type="text" class="form-control datepicker" name="startTime" readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" name="endTime" readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <!--<i class="fa fa-search"></i>-->
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <div class="row">
                        <div class="col-md-6">
                            <table id="bootstrap-table"></table>
                        </div>
                        <div class="col-md-6">
                            <div class="box direct-chat direct-chat-primary message-div">
                                <div class="box-body" id="message-box-body">
                                    <div class="direct-chat-messages" id="message-box" style="height: 700px">

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "integrate/interactive/list",
            columns: [
                {
                    title: '序号', field: 'id', width: '40',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '项目名称', field: 'name', width: '200'},
                // {title: '客户', field: 'client'},
                {title: '订单号', field: 'orderNum', width: '60'},
                {title: '代码', field: 'code', width: '80'},
                {title: '数量', field: 'num'},
                {title: '生产厂', field: 'factories',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {
                    title: '操作', width: '40',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" target="_blank" href="'+ ctx + 'board/single/' + row.id + '" onclick="event.stopPropagation();"> 查看</a> ');
                        return actions.join('');
                    }
                }
            ]
        });

        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /** 行点击事件 */
        table.on('click-row.bs.table', function (e, row, tr) {
            js.post({
                url: ctx + "integrate/interactive/message",
                data: {
                    id: row.id
                },
                success: function (result) {
                    var img = ctx + "img/avatar.png";
                    var html = [];
                    $.each(result, function (i, v) {
                        html.push('<div class="direct-chat-msg right">');
                        html.push('<div class="direct-chat-info clearfix">');
                        html.push('<span class="direct-chat-name ' + (v.sendUserId === sessionUser.id ? 'pull-right' : 'pull-left') + '">');
                        html.push(v.sendUserName);
                        html.push('</span>');
                        html.push('<span class="direct-chat-timestamp ' + (v.sendUserId === sessionUser.id ? 'pull-left' : 'pull-right') + '">');
                        html.push(v.createTime);
                        html.push('</span>');
                        html.push('</div>');
                        html.push('<img class="direct-chat-img" alt="Message User Image" src="' + (v.sendUserImage ? v.sendUserImage : img) + '">');
                        html.push('<div class="direct-chat-text">');
                        html.push(v.content);
                        html.push('</div>');
                        html.push('</div>');
                    });
                    $("#message-box").empty().append(html.join(''));
                    $("#message-box")[0].scrollTop = $("#message-box")[0].scrollHeight;
                    js.modal.closeLoading();
                }
            });
        });

        /** 跟随屏幕滚动 */
        $(".message-div").customScroll();
    });

</script>
</body>
</html>
